package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
public enum CameraType implements EnumTrans<CompleteEntity.CameraType, CameraType> {
    /**
     * CAMERA_TYPE_DEFAULT
     * CAMERA_TYPE_IP ip摄像头
     * CAMERA_TYPE_USB usb摄像头
     */
    CAMERA_TYPE_DEFAULT(CompleteEntity.CameraType.CAMERA_TYPE_DEFAULT),
    CAMERA_TYPE_IP(CompleteEntity.CameraType.CAMERA_TYPE_IP),
    CAMERA_TYPE_USB(CompleteEntity.CameraType.CAMERA_TYPE_USB),
    ;

    private final Integer id;
    private final String name;
    private final CompleteEntity.CameraType cameraType;

    CameraType(CompleteEntity.CameraType cameraType) {
        this.id = cameraType.getNumber();
        this.name = cameraType.name();
        this.cameraType = cameraType;
    }

    /**
     * @param cameraType
     * @return 对应的类型
     */
    public static CameraType getCameraType(CompleteEntity.CameraType cameraType) {
        Objects.requireNonNull(cameraType, "cameraType can not be null.");
        return Arrays.stream(CameraType.values())
                .filter(e -> e.name.equals(cameraType.name()))
                .findFirst()
                .orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
    }

    @Override
    public CompleteEntity.CameraType toProto() {
        return this.cameraType;
    }

    @Override
    public CameraType formProto(CompleteEntity.CameraType cameraType) {
        return getCameraType(cameraType);
    }
}

